package com.system.exam.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.system.exam.admin.entity.SysMenu;
import com.system.exam.admin.mapper.SysMenuMapper;
import com.system.exam.admin.service.SysMenuService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author Administrator
 * @description 针对表【sys_menu(菜单表)】的数据库操作Service实现
 * @createDate 2023-10-19 11:49:14
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
        implements SysMenuService {

    @Override
    public List<SysMenu> buildTreeMenu(List<SysMenu> sysMenuList, Boolean isGetButtonPerm) {
        List<SysMenu> resultMenuList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            for (SysMenu e : sysMenuList) {
                if (!isGetButtonPerm) {
                    if (e.getParentId() == sysMenu.getId() && !Objects.equals(e.getMenuType(), "F")) {
                        sysMenu.getChildren().add(e);
                    }
                } else {
                    if (e.getParentId() == sysMenu.getId()) {
                        sysMenu.getChildren().add(e);
                    }
                }

            }
            if (sysMenu.getParentId() == 0L) {
                resultMenuList.add(sysMenu);
            }
        }
        return resultMenuList;
    }
}




